package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProductPrivileges;
import com.ruoyi.system.service.IProductPrivilegesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专属权益Controller
 *
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/system/ProductPrivileges")
public class ProductPrivilegesController extends BaseController
{
    @Autowired
    private IProductPrivilegesService productPrivilegesService;

    /**
     * 查询专属权益列表
     */
    @PreAuthorize("@ss.hasPermi('system:ProductPrivileges:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductPrivileges productPrivileges)
    {
        startPage();
        List<ProductPrivileges> list = productPrivilegesService.selectProductPrivilegesList(productPrivileges);
        return getDataTable(list);
    }

    /**
     * 导出专属权益列表
     */
    @PreAuthorize("@ss.hasPermi('system:ProductPrivileges:export')")
    @Log(title = "专属权益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductPrivileges productPrivileges)
    {
        List<ProductPrivileges> list = productPrivilegesService.selectProductPrivilegesList(productPrivileges);
        ExcelUtil<ProductPrivileges> util = new ExcelUtil<ProductPrivileges>(ProductPrivileges.class);
        util.exportExcel(response, list, "专属权益数据");
    }

    /**
     * 获取专属权益详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ProductPrivileges:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(productPrivilegesService.selectProductPrivilegesByID(ID));
    }

    /**
     * 新增专属权益
     */
    @PreAuthorize("@ss.hasPermi('system:ProductPrivileges:add')")
    @Log(title = "专属权益", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductPrivileges productPrivileges)
    {
        return toAjax(productPrivilegesService.insertProductPrivileges(productPrivileges));
    }

    /**
     * 修改专属权益
     */
    @PreAuthorize("@ss.hasPermi('system:ProductPrivileges:edit')")
    @Log(title = "专属权益", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductPrivileges productPrivileges)
    {
        return toAjax(productPrivilegesService.updateProductPrivileges(productPrivileges));
    }

    /**
     * 删除专属权益
     */
    @PreAuthorize("@ss.hasPermi('system:ProductPrivileges:remove')")
    @Log(title = "专属权益", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(productPrivilegesService.deleteProductPrivilegesByIDs(IDs));
    }
}
